package com.beerandjesus.sportofkings.handicapper.migration.hibernate;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import java.util.List;

/**
 * Date: 3/20/15
 * Time: 11:01 PM
 */
public class SessionFactoryBuilder {
    public SessionFactory buildSessionFactory(List<Class<?>> entityClasses,
                                                      HibernateConfig hibernateConfig) {
        AnnotationConfiguration config = new AnnotationConfiguration();
        for (Class<?> entityClass : entityClasses) {
            config.addAnnotatedClass(entityClass);
        }
        config.setProperty("hibernate.dialect", hibernateConfig.getDialect());
        config.setProperty("connection.url", hibernateConfig.getUrl());
        config.setProperty("connection.driver_class", hibernateConfig.getDriverClass());
        config.setProperty("connection.username", hibernateConfig.getUsername());
        config.setProperty("connection.password", hibernateConfig.getPassword());
        config.configure();
        return config.buildSessionFactory();
    }
}
